import Vue from "vue";
import VueRouter from "vue-router";

import admin from "./admin";
import net from "./net";

Vue.use(VueRouter);

let routes = [
  // 首页
  {
    path: "/index",
    name: "index",
    component: () => import("@/pages/index.vue"),
  },
  // 移动端首页
  {
    path: "/indexMini",
    name: "indexMini",
    component: () => import("@/pages/indexMini.vue"),
  },

  // 空网页
  {
    path: "/nullPage",
    name: "nullPage",
    component: () => import("@/pages/nullPage.vue"),
  },

  // md文件目录（笔记）
  {
    path: "/mdMenu",
    name: "mdMenu",
    component: () => import("@/pages/mdMenu.vue"),
  },

  // md文件页面
  {
    path: "/theMd",
    name: "theMd",
    component: () => import("@/pages/md/theMd.vue"),
  },

  // logo页面
  {
    path: "/logo",
    name: "logo",
    component: () => import("@/pages/menu/logo.vue"),
  },

  // 友链
  {
    path: "/friendsLink",
    name: "friendsLink",
    component: () => import("@/pages/menu/friendsLink.vue"),
  },

  // 拖拽
  {
    path: "/dragAndDrop",
    name: "dragAndDrop",
    component: () => import("@/pages/play/dragAndDrop.vue"),
  },

  // 猜年龄
  {
    path: "/guessAge",
    name: "guessAge",
    component: () => import("@/pages/play/guessAge.vue"),
  },

  // 变色
  {
    path: "/Discoloration",
    name: "Discoloration",
    component: () => import("@/pages/play/Discoloration.vue"),
  },

  // 好像命令行
  {
    path: "/likeCommand",
    name: "likeCommand",
    component: () => import("@/pages/play/likeCommand.vue"),
  },

  // 好像命令行
  {
    path: "/BMInumber",
    name: "BMInumber",
    component: () => import("@/pages/play/BMInumber.vue"),
  },
  // 选中拖动
  {
    path: "/dragCheck",
    name: "dragCheck",
    component: () => import("@/pages/play/dragCheck.vue"),
  },
  // 树型结构
  {
    path: "/treeStructure",
    name: "treeStructure",
    component: () => import("@/pages/play/treeStructure.vue"),
  },
  // 表白页面
  {
    path: "/isLove",
    name: "isLove",
    component: () => import("@/pages/play/isLove/isLove.vue"),
  },
  // 屏幕时钟
  {
    path: "/screenClock",
    name: "screenClock",
    component: () => import("@/pages/play/screenClock.vue"),
  },
  // 木琴
  {
    path: "/muQin",
    name: "muQin",
    component: () => import("@/pages/play/muQin.vue"),
  },
  // 聊天
  {
    path: "/chat",
    name: "chat",
    component: () => import("@/pages/play/chat.vue"),
  },



  // 组件@/pages/play/isLove/isLove.vue
  // 目录菜单
  {
    path: "/catalogueMenu",
    name: "catalogueMenu",
    component: () => import("@/pages/components/catalogueMenu.vue"),
  },
  // 弹框提示
  {
    path: "/alert",
    name: "alert",
    component: () => import("@/pages/components/alert.vue"),
  },

  // 路由重定向
  {
    path: "*",
    redirect: "/index",
  },
];

routes = routes.concat(admin);
routes = routes.concat(net);

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
  net,
});

let originPush = VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace;
//重写push/replace
//第一个参数：告诉原来的push方法，往哪里跳转（传递哪些参数）
//第二个参数：成功的回调
//第三个参数：失败的回调
//call/apply区别
//相同点：都可以调用函数一次，都可以篡改函数的上下文(this）一次‘
//不同点：call/apply传递参数：call传递参数用逗号隔开，apply方法执行，传递数组
VueRouter.prototype.push = function (location, resolve, reject) {
  if (resolve && reject) {
    originPush.call(this, location, resolve, reject);
  } else {
    originPush.call(
      this,
      location,
      () => { },
      () => { }
    );
  }
};
VueRouter.prototype.replace = function (location, resolve, reject) {
  if (resolve && reject) {
    originReplace.call(this, location, resolve, reject);
  } else {
    originReplace.call(
      this,
      location,
      () => { },
      () => { }
    );
  }
};

export default router;
